package com.guigu.tankai.controller;

import com.guigu.liuyunan.pojo.Order;
import com.guigu.tankai.pojo.Memberexamination;
import com.guigu.tankai.service.MemService;
import com.guigu.tankai.service.MemberexService;
import com.guigu.tankai.service.SetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.UUID;

@RestController

public class Memberexcontroller {

    @Autowired
    MemberexService memb;
    @Autowired
    MemService men;
    @Autowired
    SetService setService;


    @RequestMapping("tkdelmemb")
    public int deleteByPrimaryKey(Integer id) {
        return memb.deleteByPrimaryKey(id);
    }

    @RequestMapping("tkinsertmemb")
    public int insertSelective(Memberexamination record) {
        return memb.insertSelective(record);
    }

    @RequestMapping("tkselememb")
    public Memberexamination selectByPrimaryKey(Integer id) {
        return memb.selectByPrimaryKey(id);
    }

    @RequestMapping("tkupdememb")
    public int updateByPrimaryKey(@RequestBody Memberexamination record) {
        return memb.updateByPrimaryKey(record);
    }

    @RequestMapping("tankaiUp")
    public int tankaiUp(@RequestParam("pictureFile") MultipartFile pictureFile,
                        Order order) throws Exception {
        // 图片上传
        // 设置图片名称，不能重复，可以使用uuid
        String picName = UUID.randomUUID().toString();
        // 获取文件名
        String oriName = pictureFile.getOriginalFilename();
        // 获取图片后缀
        String extName = oriName.substring(oriName.lastIndexOf("."));
        File file=new File("C:\\Users\\a\\Desktop\\项目\\vue-element-ui--demo\\Rear\\html\\src/image");
        if (!file.exists()){
            file.mkdirs();
        }
        // 开始上传
        pictureFile.transferTo(new File(file+"/" + picName + extName));

        // 设置图片名到商品中
        // item.setPic(picName + extName);
        order.setImg(picName+extName);
        // ---------------------------------------------
        // 更新商品
        //this.itemService.updateItemById(item);
        return memb.tankaiUp(order);
    }




}
